package second.string;

/**
 * @author: heweiwei
 * @Date: 2023/1/29 11:18
 * @Desc:
 */
public class StringTest {

    public static void main(String[] args) {


        String str1 = new StringBuffer("byte").append("code").toString();
        str1.intern();
        System.out.println(str1 == str1.intern());

        String str2 = new StringBuffer("open1").append("jdk").toString();
        str2.intern();
        System.out.println(str2 == str2.intern());


    }

    public static int rebuildNum(int num) {
        if (num <= 0) {
            //如果num<=0，直接返回2的0次幂
            return 1;
        } else if ((num & (num - 1)) == 0) {
            //如果num是2的乘方，则直接返回num
            return num;
        } else {
            //找到大于以2为底num的对数最近的整数
            //例：num=7,以2为底7的对数为：2.807...，强转int再加1结果为：3
            int tmp = (int) (Math.log(num) / Math.log(2)) + 1;
            //求2的tmp次幂
            return (int) Math.pow(2, tmp);
        }
    }


    public static int getTheMixTwoOfOneNumber(int number) {
        if (number <= 0) {
            return 1;
        } else if ((number & number - 1) == 0) {
            return number;
        } else {
            int temp = (int) (Math.log(number) / Math.log(2)) + 1;
            return (int) Math.pow(temp, 2);
        }
    }


}
